package com.yuexun.dhdoctor.module.meeting.presenter.impl;

import com.yuexun.dhdoctor.module.meeting.bean.MeetingBeanCheckBean;
import com.yuexun.dhdoctor.module.meeting.bean.MeetingCheckStateBean;
import com.yuexun.dhdoctor.module.meeting.bean.MeetingDetailBean;
import com.yuexun.dhdoctor.module.meeting.model.IMeetingDetailModel;
import com.yuexun.dhdoctor.module.meeting.presenter.IMeetingDetailPresenter;
import com.yuexun.dhdoctor.module.meeting.ui.view.IMeetingDetailView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2016/11/15.
 */
public class MeetingDetailPresenter implements IMeetingDetailPresenter {
    private IMeetingDetailView view;
    private IMeetingDetailModel model;

    public MeetingDetailPresenter(IMeetingDetailModel model, IMeetingDetailView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getMeetingDetail(Map<String, String> praise) {
        model.getMeetingDetail(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<MeetingDetailBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("网络连接失败，请检查网络连接");
                    }

                    @Override
                    public void onNext(MeetingDetailBean meetingDetailBean) {
                        view.showMeetingDetail(meetingDetailBean);
                    }
                });
    }

    @Override
    public void getMeetingCheckState(Map<String, String> praise) {
        model.getMeetingCheckState(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<MeetingCheckStateBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("查询签到状态失败,请检查网络连接");
                    }

                    @Override
                    public void onNext(MeetingCheckStateBean meetingCheckStateBean) {
                        view.showMeetingCheckState(meetingCheckStateBean);
                    }
                });
    }

    @Override
    public void getMeetingCheck(Map<String, String> praise) {
        model.getMeetingCheck(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<MeetingBeanCheckBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("签到失败请求失败,请检查网络连接");
                    }

                    @Override
                    public void onNext(MeetingBeanCheckBean meetingBeanCheckBean) {
                        view.showMeetingCheck(meetingBeanCheckBean);
                    }
                });
    }
}
